<%--
  Created by IntelliJ IDEA.
  User: fire'ge
  Date: 2022/4/29
  Time: 13:47
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>
<html>
<head>
    <title>购物车</title>
    <link rel="stylesheet" href="/TakeawaySystem/css/Show.css" type="text/css">
</head>
<body>
<div>
    <table id="name-label">
        <tr>
            <td align="center" colspan="4">你好！${user.username}
                <a href="/TakeawaySystem/jsp/UserCenter.jsp">退出</a>  </td>
        </tr>
    </table>
    <table>
        <tr>
            <td id= "tableTopic">
                购 物 车 清 单
            </td>
        </tr>
        <c:if test="${foods.size()>0}">

        <c:forEach begin="0" end="${foods.size()-1}" var="i">

            <form id="bookForm${i}" method="post">
                <tr>
                    <td class="shopTopic">
                        菜名：${foods[i].dishName}

                    </td>
                </tr>
                <tr>
                    <td class="description">
                        描述：${foods[i].description}
                    </td>
                </tr>
                <td>
                    ${carts[i].cartNum}份
                </td>
                <td>
                    <input type="hidden" id="foodSize" value="${foods.size()}" >
                    <input type="hidden" value="${carts[i].cartNum}" name="dishNum">
                    <input type="hidden" value="${foods[i].id}" name="foodId">
                    <input type="hidden" value="${carts[i].id}" name="cartId">
                    <input type="hidden" value="${shopId}" name="shopId">
                    <input Type="submit" id="book${i}" name="book" Value="下 订" >
                    <input Type="submit" id="delete${i}" name="delete" Value="删 除" >
                </td>
            </form>
        </c:forEach>
        </c:if>
    </table>
</div>
</body>
<Script Language="JavaScript">
    let foodSize = document.getElementById("foodSize").value;
    for (let i = 0; i < foodSize; i++) {
        let book = document.getElementById("book"+i);
        book.onclick = addBook;

        function addBook() {
            document.getElementById("bookForm"+i).action = "addCartBook";
            document.getElementById("bookForm"+i).submit();
        }

        let delete_ = document.getElementById("delete"+i);
        delete_.onclick = deleteCart;

        function deleteCart() {
            document.getElementById("bookForm"+i).action = "user/deleteCart";
            document.getElementById("bookForm"+i).submit();
        }
    }

</Script>
</html>
